package com.cabal.common.util;

import com.cabal.common.encrypt.AESUtils;
import sun.misc.BASE64Encoder;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class DatFileUtil {

    public static void writeEncryptedDataToFile(String filename, String[] lines, String key) {
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
            for (String line : lines) {
                String encryptedLine = AESUtils.encrypt(line, key);
                writer.write(encryptedLine);
                // 新行分隔符，确保每行是单独的加密数据
                writer.newLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String[] linesToWrite_local = {
                "launcher_hostname=http://127.0.0.1:19003/api/cabal/cabalUpdateClient/",
                "common_hostname=http://127.0.0.1:19003/cabal/common/",
                "ws_hostname=ws://127.0.0.1:19003/websocket/",
                "client_version=1.0.0",
                "md5_key=98cddda9c2344685ab6ab391867bd275"};

        String[] linesToWrite_pro = {
                "launcher_hostname=http://47.113.224.57:19003/api/cabal/cabalUpdateClient/",
                "common_hostname=http://47.113.224.57:19003/cabal/common/",
                "ws_hostname=ws://47.113.224.57:19003/websocket/",
                "client_version=1.2.8",
                "md5_key=98cddda9c2344685ab6ab391867bd275"};


       String[] linesToWrite_test = {
                "launcher_hostname=http://8.155.51.248:19003/api/cabal/cabalUpdateClient/",
                "common_hostname=http://8.155.51.248:19003/cabal/common/",
                "ws_hostname=ws://8.155.51.248:19003/websocket/",
                "client_version=1.1.9",
                "md5_key=98cddda9c2344685ab6ab391867bd275"};

        String[] linesToWrite_fy_test = {
                "launcher_hostname=http://47.121.115.95:19003/api/cabal/cabalUpdateClient/",
                "common_hostname=http://47.121.115.95:19003/cabal/common/",
                "ws_hostname=ws://47.121.115.95:19003/websocket/",
                "client_version=1.0.0",
                "md5_key=98cddda9c2344685ab6ab391867bd275"};

        String fileName = "C:\\Users\\Administrator\\Desktop\\config.dat";
        //String fileName = "D:\\\\360MoveData\\\\Users\\\\user\\\\Desktop\\\\kylin.dat";
        writeEncryptedDataToFile(new File(fileName).getPath(), linesToWrite_fy_test, AESUtils.ENCRY_KEY);
        //File file = new File("D:\\360MoveData\\Users\\user\\Desktop\\kylin.dat");
        //writeEncryptedDataToFile("D:\\360MoveData\\Users\\user\\Desktop\\kylin.dat", linesToWrite_test, AESUtils.ENCRY_KEY);
    }


}
